
<script type='text/javascript'>
    $(document).ready(function() {

        var d = new Date();
        var y = d.getFullYear();
        var m = d.getMonth();

        $('#calendar').fullCalendar({

            eventClick: function(calEvent, jsEvent, view) {
                $.get("reservacion/edit?idreservacion= "+calEvent.id, function(data){
                    // create a modal dialog with the data
                    $(data).modal({
                        onOpen: function (dialog) {
                            dialog.overlay.fadeIn('fast', function () {
                                dialog.container.slideDown('fast', function () {
                                    dialog.data.fadeIn('fast');
                                });
                            });
                        },
                        onClose: function (dialog) {
                            dialog.container.slideUp('slow', function () {
                                dialog.overlay.fadeOut('slow', function () {
                                    $.modal.close(); // must call this!
                                });
                            });
                        }
                    });
                });
            },
            dayClick: function(date, allDay, jsEvent, view) {
                if (allDay) {
                    // load the contact form using ajax
            dia = date.getDate()
            mes = date.getMonth()+1
            anio = date.getFullYear()
            $.get("reservacion/new?dia= "+anio+"/"+mes+"/"+dia,function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                            onOpen: function (dialog) {
                                dialog.overlay.fadeIn('fast', function () {
                                    dialog.container.slideDown('fast', function () {
                                        dialog.data.fadeIn('fast');
                                    });
                                });
                            },
                            onClose: function (dialog) {
                                dialog.container.slideUp('slow', function () {
                                    dialog.overlay.fadeOut('slow', function () {
                                        $.modal.close(); // must call this!
                                    });
                                });
                            }
                        });
                    });
                }
                else{
                    // load the contact form using ajax
                    dia = date.getDate()
                    mes = date.getMonth()+1
                    anio = date.getFullYear()
                    hinicio = date.getHours()
                    minicio = date.getMinutes()
                    $.get("reservacion/new?dia= "+anio+"/"+mes+"/"+dia+"& horaIni="+hinicio+":"+minicio, function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                            onOpen: function (dialog) {
                                dialog.overlay.fadeIn('fast', function () {
                                    dialog.container.slideDown('fast', function () {
                                        dialog.data.fadeIn('fast');
                                    });
                                });
                            },
                            onClose: function (dialog) {
                                dialog.container.slideUp('slow', function () {
                                    dialog.overlay.fadeOut('slow', function () {
                                        $.modal.close(); // must call this!
                                    });
                                });
                            }
                        });
                    });
                }
            },
            monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
                'Julio','Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],

            dayNames: ['Domingo','Lunes','Martes','Miercoles','Jueves','Viernes',
                'Sabado'],

            monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun',
                'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],

            dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],

            header:{left: 'agendaWeek,agendaDay' ,right:'today prev,next',center:'title'},
            buttonText: {today:'Hoy',week:'Semana',day:'Día'},
            columnFormat: {week: 'ddd d'},
            titleFormat: {day: 'MMM d, yyyy'},
            defaultView: 'agendaDay',
            allDaySlot: false,
            draggable: true,
            events: [
<?php $total = count($Reservacions);
$i=0; ?>
<?php foreach ($Reservacions as $intra_cal): ?>
    <?php $i++; ?>
    <?php
    $fecha = strtotime($intra_cal->getFecha());
    $anno = date("Y", $fecha);
    $mes = date("m", $fecha);
    $mes--;
    $dia = date("d", $fecha);
    $tiempo = strtotime($intra_cal->getHoraInicio());
    ;
    $horaIni = date("H", $tiempo);
    $minutosIni = date("i", $tiempo);
    $tiempoFin = strtotime($intra_cal->getHoraFin());
    ;
    $horaFin = date("H", $tiempoFin);
    $minutosFin = date("i", $tiempoFin);
    ?>
                    {
                        allDay: false,
                        id: <?php echo $intra_cal->getIdReservacion() ?>,
                        title: "<?php //echo $intra_cal->getIdSala()
                                       $sala = SalaPeer::retrieveByPK($intra_cal->getIdSala());
                                       echo "Sala: ".$sala->getNombre().'\n';
                                       $banda = BandaPeer::retrieveByPK($intra_cal->getIdBanda());
                                       echo "Banda: ".$banda->getNombre();
                                       ?>",
                        start: <?php echo "new Date(".$anno.", ".$mes.", ".$dia.", ".$horaIni.", ".$minutosIni.")"; ?>,
                        end: <?php echo "new Date(".$anno.", ".$mes.", ".$dia.", ".$horaFin.", ".$minutosFin.")"; ?>

                    }<?php if ($i != $total) echo "," ?><?php endforeach; ?>
                ]
            })

        });
</script>
<div id='calendar'align="center" style="width:540px"></div>
